package com.example.demo.utils;

import java.util.List;

public class Result {
    // 错误码
    private int code;
    // 错误返回信息
    private String msg;
    // 返回结果集
    private Object data = null;

    public static Result success(Object object) {
        Result result = new Result();
        result.setCode(0);
        result.setMsg("操作成功");
        result.setData(object);
        return result;
    }

    public static Result success() {
        Result result = new Result();
        result.setCode(0);
        result.setMsg("操作成功");
        result.setData("");
        return result;
    }

    public static Result success(Object data, String msg) {
        Result result = new Result();
        result.setCode(0);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result fail(Object data, String msg) {
        Result result = new Result();
        result.setCode(-1);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result fail(Object data) {
        Result result = new Result();
        result.setCode(-1);
        result.setMsg("操作失败");
        result.setData(data);
        return result;
    }

    public static Result fail(int code, Object data, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public int getCode() {
        return code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setCode(int code) {
        this.code = code;
    }

}
